var express = require('express')

var router = express.Router()

// 导入MySQL模
var mysql = require('mysql')

var mysqlConfig = require('../../config/mysql')

// 连接池
var pool = mysql.createPool(mysqlConfig)

// uid模块 
var UUID = require('node-uuid');

function getuid() {
    return UUID.v1().replace(/(-)/g, '')
}

//默认
router.get('/', function (req, res, next) {
    res.send('接口路径不完整')
    next()
});

//新增用户
router.get('/addUser', (req, res, next) => {
    pool.getConnection((err, connection) => {

        //参数
        const {
            user_account,
            user_name
        } = req.query

        connection.query(`INSERT INTO user_table( uid, user_account, user_name, user_identity ) VALUES( "${getuid()}", "${user_account}", "${user_name}", "${1}" )`, (err, result) => {
            if (!err) {
                results = {
                    code: 200,
                    msg: '新增用户成功',
                };
                res.json(results)
            } else {
                res.json({
                    code: 500,
                    msg: '新增用户失败',
                    err
                });
            }
            connection.release()
        })

    })
})

module.exports = router